Fix unable to import in node 12.18 ESM#77
Merged
Conversation
guybedford
approved these changes
Jul 5, 2021
guybedford
left a comment
Owner
There was a problem hiding this comment.
Thanks for the PR.
I also just noticed this one myself. The issue here is Node.js 12.18 doesn't yet supported the named exports for CJS feature, and as a result the package must be imported via import lexer from 'es-module-lexer'.
Fixing this via conditional exports seems good to me.
Co-authored-by: Guy Bedford <guybedford@gmail.com>
guybedford
reviewed
Jul 5, 2021
guybedford
left a comment
Owner
There was a problem hiding this comment.
Ok, merging and releasing now.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds some fields to
package.jsonto be able to use this library with native ESM mode in node 12.18 and upwards. Without these node fails with the following error:(node:1744) ExperimentalWarning: The ESM module loader is experimental. file:///opt/build/repo/packages/wmr/src/lib/transform-imports.js:1 import { parse } from 'es-module-lexer'; ^^^^^ SyntaxError: The requested module 'es-module-lexer' does not provide an export named 'parse' at ModuleJob._instantiate (internal/modules/esm/module_job.js:92:21) at async ModuleJob.run (internal/modules/esm/module_job.js:107:20) at async Loader.import (internal/modules/esm/loader.js:179:24)Ran into this while working on preactjs/wmr#715 .
Explanation of the fix:
Fixes #54 .